package com.health.tablebean.webservice;

import android.content.Context;
import android.text.TextUtils;


import com.health.db.FDbManager;
import com.health.tablebean.GRAVIDA_BASEINFO;
import com.health.tablebean.GRAVIDA_TWO2FIVE_FOLLOWUP;
import com.health.viewscontrols.NovaApplication;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * 第2-5次产前随访接口参数
 *
 * @author wangxiangyi
 * @date 2018/04/21
 */
public class SecondToFifthPrenatalVisits {

    /**
     * 身份证（现做证件号码）
     */
    private String cardid;
    /**
     * 产次：
     * DM06-05_1 第一胎，
     * DM06-05_2 第二胎，
     * DM06-05_3 第三胎，
     * DM06-05_4 第四胎，
     * DM06-05_5 第五胎
     */
    private String fetusTimes;
    /**
     * 填表日期
     */
    private String visitDate;
    /**
     * 孕周
     */
    private String gestationWeeks;
    /**
     * 主诉
     */
    private String patientsReport;
    /**
     * 宫底高度（cm)
     */
    private String fundusUterus;
    /**
     * 下次汸视日期
     */
    private String nextVisitDate;
    /**
     * 访视医师姓名
     */
    private String visitDoctorName;
    /**
     * 创建人
     */
    private String creater;
    /**
     * 创建机构
     */
    private String createorg;
    /**
     * 随访次数， 1 产前第一次随访 2~5 分别表示产前第2次到第5次随访'
     */
    private String visitTimes;
    /**
     * 腹部周长的测量值，计量单位为cm
     */
    private String abdomenCircumference;
    /**
     * 体重的测量值，计量单位为kg
     */
    private String bodyWeight;
    /**
     * 舒张压（mm Hg)
     */
    private String dbp;
    /**
     * 胎心率（次/min)
     */
    private String fetalHr;
    /**
     * 胎方位代码：
     * DM06-04_1	左枕前(LOA)
     * <p>
     * DM06-04_2	右枕前(ROA)
     * <p>
     * DM06-04_3	左枕后(LOD)
     * <p>
     * DM06-04_4	右枕后(RoP)
     * <p>
     * DM06-04_5	左枕横(LoT)
     * <p>
     * DM06-04_6	右枕横(RoT)
     * <p>
     * DM06-04_7	左颏前(LMA)
     * <p>
     * DM06-04_8	右颏前(RMA)
     * <p>
     * DM06-04_9	左颏后(LMP)
     * <p>
     * DM06-04_10	右颏后(RMP)
     * <p>
     * DM06-04_11	左颏横(LMT)
     * <p>
     * DM06-04_12	右颏横(RMT)
     * <p>
     * DM06-04_13	左骶前(LsA)
     * <p>
     * DM06-04_14	右骶前(RsA)
     * <p>
     * DM06-04_15	左骶后(LsP)
     * <p>
     * DM06-04_16	右骶后(RsP)
     * <p>
     * DM06-04_17	左骶横(LsT)
     * <p>
     * DM06-04_18	右骶横(R)
     * <p>
     * DM06-04_19	左肩前(LscA)
     * <p>
     * DM06-04_20	右肩前(RscA)
     * <p>
     * DM06-04_21	左肩后(LscP)
     * <p>
     * DM06-04_22	右肩后(RscP)
     * <p>
     * DM06-04_23	不详
     * <p>
     * DM06-04_99	不固定
     */
    private String fetalPosition;
    /**
     * 血红蛋白值（g/L)
     */
    private String haematoglobin;
    /**
     * 转诊原因、转诊机构及科室
     */
    private Rollout hdPersonalRollOut;
    /**
     * 孕产妇健康评估异常结果描述
     */
    private String maternalHealthDesc;
    /**
     * 保健指导：
     * DM06-03_15	生活方式，
     * DM06-03_2	心理，
     * DM06-03_14	营养，
     * DM06-03_6	运动，
     * DM06-03_17	自我监护，
     * DM06-03_9	母乳喂养，
     * DM06-03_8	分娩准备
     * DM06-03_99	其他，
     */
    private String maternalHealthGuide;
    /**
     * 保健指导 其他
     */
    private String maternalHealthOther;
    /**
     * 孕产妇健康评估异常标志：
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String maternalHealthSign;
    /**
     * 其他辅助检查
     */
    private String otherAuxiliaryExamination;
    /**
     * 标记是否转诊：
     * DM01-11_1 无，
     * DM01-11_2 有
     */
    private String res1;
    /**
     * 收缩压（mmHg)
     */
    private String sbp;
    /**
     * 尿蛋白定性检测结果代码：
     * DM100-38_1	—，
     * DM100-38_2	±，
     * DM100-38_3	+，
     * DM100-38_4	++，
     * DM100-38_5	+++，
     * DM100-38_6	++++
     */
    private String urineProteinValue;

    public String getCardid() {
        return cardid;
    }

    public void setCardid(String cardid) {
        this.cardid = cardid;
    }

    public String getFetusTimes() {
        return fetusTimes;
    }

    public void setFetusTimes(String fetusTimes) {
        this.fetusTimes = fetusTimes;
    }

    public String getVisitDate() {
        return visitDate;
    }

    public void setVisitDate(String visitDate) {
        this.visitDate = visitDate;
    }

    public String getGestationWeeks() {
        return gestationWeeks;
    }

    public void setGestationWeeks(String gestationWeeks) {
        this.gestationWeeks = gestationWeeks;
    }

    public String getPatientsReport() {
        return patientsReport;
    }

    public void setPatientsReport(String patientsReport) {
        this.patientsReport = patientsReport;
    }

    public String getFundusUterus() {
        return fundusUterus;
    }

    public void setFundusUterus(String fundusUterus) {
        this.fundusUterus = fundusUterus;
    }

    public String getNextVisitDate() {
        return nextVisitDate;
    }

    public void setNextVisitDate(String nextVisitDate) {
        this.nextVisitDate = nextVisitDate;
    }

    public String getVisitDoctorName() {
        return visitDoctorName;
    }

    public void setVisitDoctorName(String visitDoctorName) {
        this.visitDoctorName = visitDoctorName;
    }

    public String getCreater() {
        return creater;
    }

    public void setCreater(String creater) {
        this.creater = creater;
    }

    public String getCreateorg() {
        return createorg;
    }

    public void setCreateorg(String createorg) {
        this.createorg = createorg;
    }

    public String getVisitTimes() {
        return visitTimes;
    }

    public void setVisitTimes(String visitTimes) {
        this.visitTimes = visitTimes;
    }

    public String getAbdomenCircumference() {
        return abdomenCircumference;
    }

    public void setAbdomenCircumference(String abdomenCircumference) {
        this.abdomenCircumference = abdomenCircumference;
    }

    public String getBodyWeight() {
        return bodyWeight;
    }

    public void setBodyWeight(String bodyWeight) {
        this.bodyWeight = bodyWeight;
    }

    public String getDbp() {
        return dbp;
    }

    public void setDbp(String dbp) {
        this.dbp = dbp;
    }

    public String getFetalHr() {
        return fetalHr;
    }

    public void setFetalHr(String fetalHr) {
        this.fetalHr = fetalHr;
    }

    public String getFetalPosition() {
        return fetalPosition;
    }

    public void setFetalPosition(String fetalPosition) {
        this.fetalPosition = fetalPosition;
    }

    public String getHaematoglobin() {
        return haematoglobin;
    }

    public void setHaematoglobin(String haematoglobin) {
        this.haematoglobin = haematoglobin;
    }

    public Rollout getHdPersonalRollOut() {
        return hdPersonalRollOut;
    }

    public void setHdPersonalRollOut(Rollout hdPersonalRollOut) {
        this.hdPersonalRollOut = hdPersonalRollOut;
    }

    public String getMaternalHealthDesc() {
        return maternalHealthDesc;
    }

    public void setMaternalHealthDesc(String maternalHealthDesc) {
        this.maternalHealthDesc = maternalHealthDesc;
    }

    public String getMaternalHealthGuide() {
        return maternalHealthGuide;
    }

    public void setMaternalHealthGuide(String maternalHealthGuide) {
        this.maternalHealthGuide = maternalHealthGuide;
    }

    public String getMaternalHealthOther() {
        return maternalHealthOther;
    }

    public void setMaternalHealthOther(String maternalHealthOther) {
        this.maternalHealthOther = maternalHealthOther;
    }

    public String getMaternalHealthSign() {
        return maternalHealthSign;
    }

    public void setMaternalHealthSign(String maternalHealthSign) {
        this.maternalHealthSign = maternalHealthSign;
    }

    public String getOtherAuxiliaryExamination() {
        return otherAuxiliaryExamination;
    }

    public void setOtherAuxiliaryExamination(String otherAuxiliaryExamination) {
        this.otherAuxiliaryExamination = otherAuxiliaryExamination;
    }

    public String getRes1() {
        return res1;
    }

    public void setRes1(String res1) {
        this.res1 = res1;
    }

    public String getSbp() {
        return sbp;
    }

    public void setSbp(String sbp) {
        this.sbp = sbp;
    }

    public String getUrineProteinValue() {
        return urineProteinValue;
    }

    public void setUrineProteinValue(String urineProteinValue) {
        this.urineProteinValue = urineProteinValue;
    }

    /**
     * 第一次产前访视接口参数
     *
     * @param context 上下文
     * @param flag    2：第2次产前随访、
     *                3：第3次产前随访、
     *                4：第4次产前随访、
     *                5：第5次产前随访
     * @return
     */
    public static List<SecondToFifthPrenatalVisits> convertData(Context context, String flag) {
        List<SecondToFifthPrenatalVisits> datas = new ArrayList<>();

        FDbManager fdb = FDbManager.getInstance(context);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        if (null == NovaApplication.getUserInfo()) {
            return datas;
        }
        List<GRAVIDA_TWO2FIVE_FOLLOWUP> infos = fdb.findAllByWhere(GRAVIDA_TWO2FIVE_FOLLOWUP.class,
                "IDCARD='" + NovaApplication.getUserInfo().getIDCARD() + "'AND TIMES ='" + flag + "'");

        if (infos != null && !infos.isEmpty()) {
            for (GRAVIDA_TWO2FIVE_FOLLOWUP info : infos) {
                SecondToFifthPrenatalVisits secondToFifthPrenatalVisits = new SecondToFifthPrenatalVisits();
                /* 2：第2次产前随访、3：第3次产前随访、 4：第4次产前随访、 5：第5次产前随访*/
                switch (flag) {
                    case "2":
                        secondToFifthPrenatalVisits.setVisitTimes(flag);
                        break;
                    case "3":
                        secondToFifthPrenatalVisits.setVisitTimes(flag);
                        break;
                    case "4":
                        secondToFifthPrenatalVisits.setVisitTimes(flag);
                        break;
                    case "5":
                        secondToFifthPrenatalVisits.setVisitTimes(flag);
                        break;
                    default:
                        secondToFifthPrenatalVisits.setVisitTimes("");
                        break;
                }
                /*身份证号*/
                secondToFifthPrenatalVisits.setCardid(TextUtils.isEmpty(info.getIDCARD()) ? "" : info.getIDCARD().toUpperCase());
                /*获取孕妇基本信息*/
                List<GRAVIDA_BASEINFO> gradicas = fdb.findAllByWhere(GRAVIDA_BASEINFO.class,
                        "IDCARD = '" + info.getIDCARD() + "'");
                if (gradicas.size() > 0) {
                    /*产次*/
                    secondToFifthPrenatalVisits.setFetusTimes(TextUtils.isEmpty(gradicas.get(0).getFetusTimes()) ? "" : gradicas.get(0).getFetusTimes());
                }
                /*随访/督促*/
                if (info.getFOLLOWUP_DATE() != null) {
                    secondToFifthPrenatalVisits.setVisitDate(formatter.format(info.getFOLLOWUP_DATE()));
                }
                /*孕周*/
                secondToFifthPrenatalVisits.setGestationWeeks(TextUtils.isEmpty(info.getPREGANCYWEEKS()) ? "" : info.getPREGANCYWEEKS());
                /*主诉*/
                secondToFifthPrenatalVisits.setPatientsReport(TextUtils.isEmpty(info.getCHIEFCOMPLAINT()) ? "" : info.getCHIEFCOMPLAINT());
                /*体重*/
                secondToFifthPrenatalVisits.setBodyWeight(TextUtils.isEmpty(info.getWEIGHT()) ? "" : info.getWEIGHT());
                /*妇科检查：宫底高度*/
                secondToFifthPrenatalVisits.setFundusUterus(TextUtils.isEmpty(info.getUTERUSLOWHEIGHT()) ? "" : info.getUTERUSLOWHEIGHT());
                /*妇科检查：腹围*/
                secondToFifthPrenatalVisits.setAbdomenCircumference(TextUtils.isEmpty(info.getABDOMINALCIRUMFERENCE()) ? "" : info.getABDOMINALCIRUMFERENCE());
                /*妇科检查：胎位*/
                secondToFifthPrenatalVisits.setFetalPosition(TextUtils.isEmpty(info.getFETUSPOSITION()) ? "" : info.getFETUSPOSITION());
                /*妇科检查：胎心率*/
                secondToFifthPrenatalVisits.setFetalHr(TextUtils.isEmpty(info.getFHR()) ? "" : info.getFHR());
                /*收缩血压*/
                secondToFifthPrenatalVisits.setSbp(TextUtils.isEmpty(info.getHBLOODPRESSURE()) ? "" : info.getHBLOODPRESSURE());
                /*舒长血压*/
                secondToFifthPrenatalVisits.setDbp(TextUtils.isEmpty(info.getLBLOODPRESSURE()) ? "" : info.getLBLOODPRESSURE());
                /*血红蛋白*/
                secondToFifthPrenatalVisits.setHaematoglobin(TextUtils.isEmpty(info.getHB()) ? "" : info.getHB());
                /*尿常规：尿蛋白*/
                secondToFifthPrenatalVisits.setUrineProteinValue(TextUtils.isEmpty(info.getPRO()) ? "" : info.getPRO());
                /*其他辅助检查*/
                secondToFifthPrenatalVisits.setOtherAuxiliaryExamination(TextUtils.isEmpty(info.getASSISTANTEXAM()) ? "" : info.getASSISTANTEXAM());
                /*分类*/
                secondToFifthPrenatalVisits.setMaternalHealthSign(TextUtils.isEmpty(info.getCLASSIFICATION()) ? "" : info.getCLASSIFICATION());
                /*分类异常*/
                secondToFifthPrenatalVisits.setMaternalHealthDesc(TextUtils.isEmpty(info.getCLASSIFICATION_EX()) ? "" : info.getCLASSIFICATION_EX());
                /*指导*/
                secondToFifthPrenatalVisits.setMaternalHealthGuide(TextUtils.isEmpty(info.getADVISING()) ? "" : info.getADVISING());
                /*指导异常*/
                secondToFifthPrenatalVisits.setMaternalHealthOther(TextUtils.isEmpty(info.getADVISINGOTHER()) ? "" : info.getADVISINGOTHER());
                /*转诊*/
                secondToFifthPrenatalVisits.setRes1(TextUtils.isEmpty(info.getREFERRAL()) ? "" : info.getREFERRAL());
                /*转诊原因、机构及科室*/
                Rollout rollOut = new Rollout();
                rollOut.setHpc(info.getREFERRALREASON());
                rollOut.setRollInRegion(info.getREFERRALORG());
                secondToFifthPrenatalVisits.setHdPersonalRollOut(rollOut);
                /*下次随访时间*/
                if (info.getNEXTFOLLOWUP_DATE() != null) {
                    secondToFifthPrenatalVisits.setNextVisitDate(formatter.format(info.getNEXTFOLLOWUP_DATE()));
                }
                /*随访医生签名*/
                secondToFifthPrenatalVisits.setVisitDoctorName(TextUtils.isEmpty(info.getFOLLOWUPDOCTOR()) ? "" : info.getFOLLOWUPDOCTOR());
                /*创建人*/
                secondToFifthPrenatalVisits.setCreater(TextUtils.isEmpty(info.getCREATER()) ? "" : info.getCREATER());
                /*创建机构*/
                secondToFifthPrenatalVisits.setCreateorg(TextUtils.isEmpty(info.getCREATEORG()) ? "" : info.getCREATEORG());
                /*添加list里面*/
                datas.add(secondToFifthPrenatalVisits);
            }
        }
        return datas;
    }
}